﻿<!DOCTYPE html>
<html lang="en" window-frame="solid" window-icon="./view/icon/server-favicon.ico"></html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="./view/css/index.css">
</head>
<body id="body" role="window-caption">
	<div id="enterbox">
		<!-- 提示  -->
        <div id="messtip">
			<i id="messtipicon" class="successicon"></i>
			<span class="messtipword">
				<span class="reminderhandle"></span>
				<span class="errorhandle"></span> 
			</span>
		</div>
		<!-- 提示 -->
		<div class="logobox fl">
			<div class="lg_top">
				<img src="./view/img/logobox-logo.png" alt="">
			</div>
			<div class="lg_bottom">
				版本号&nbsp;1.2.1
			</div>
		</div>
		<div class="loginbox fr">
			<div class="head">
				<div class="setting fr" style="width:60px;">
					<ul>
						<li><button id="minimized" class="minimizedicon loginicon"></button></li>
						<li><button id="closewin" class="closewinicon loginicon"></button></li>
					</ul>
				</div>
			</div>
			<h2 class="_title_reg"></h2>
			<form action="">
				<div class="input_item">
					<input type="text" name="name" class="loginicon nameicon" >
				</div> 
				<div class="input_item">
					<input type="text" name="email" class="loginicon emailicon">
				</div>
				<div class="input_item">
					<input type="password" name="pass" class="loginicon passwordicon">
				</div>
				<span class="alertspan" style="margin-left:70px;color:#ff0000;font-size: 14PX;"> <i></i> 请输入正确的邮箱</span>
				<div class="input_item" style="margin-top:35px">
					<button id="register" class="submit">注册</button>
					<br />
					<button id="login_index" class="register">立即登录</button>
				</div>
			</form>
		</div>
		
	</div>
	<script type="text/tiscript" src="./view/tiscript/index.tis"></script>
	<script type="text/tiscript" src="./view/tiscript/public.tis"></script>
	<script type="text/tiscript">
		moveToScreenCenter(672,517);

		$(#messtip).style["display"] = "none"
		$(#login_index).on("click",function(){
			view.load("./view/login.html",false);
		});
		$(#register).on("click",function(){
			var name = $(input[name=name]).value;
			var pass = $(input[name=pass]).value;
			var email = $(input[name=email]).value;
			
			if(name && pass && email){
				var res = view.register(email,pass,name)
				if (res.success) {
				    $(#messtip).style["display"] = "block"
	  				$(#messtipicon).attributes["class"] = "successicon"
				    $(.reminderhandle).text = "注册成功"
					$(.errorhandle).text = ""
					var cnt = 3;
					self.timer(500, function() {
						if(cnt <= 0) {
							//返回false则停止定时器
							loginfun(email,pass)
							return false;
						}
						cnt--;
						$(#register).text="正在登陆" + cnt + "s"
						return true;
					});
					reminder()
				}else{
					$(#messtip).style["display"] = "block"
					$(#messtipicon).attributes["class"] = "defeaticon"
				    $(.reminderhandle).text = "注册失败"
				    $(.errorhandle).text = res.msg
					reminder()
				}
			}else{
				$(#messtip).style["display"] = "block"
				$(#messtipicon).attributes["class"] = "defeaticon"
				$(.reminderhandle).text = "注册失败"
				$(.errorhandle).text = "请输入正确信息"
			}
		});
		$(input[name=name]).value = "请输入用户名"
		$(input[name=name]).style["color"] = "#ccc"
		$(input[name=email]).value = "请输入正确邮箱"
		$(input[name=email]).style["color"] = "#ccc"
		$(input[name=name]).on("focus",function(){
			$(input[name=name]).style["color"] = "#000"
			if($(input[name=name]).value == "请输入用户名"){
				$(input[name=name]).value = ""
			}
		})
		$(input[name=name]).on("blur",function(){
			if($(input[name=name]).value == ""){
				$(input[name=name]).value = "请输入用户名"
				$(input[name=name]).style["color"] = "#ccc"
			}
		})
		$(input[name=email]).on("focus",function(){
			$(input[name=email]).style["color"] = "#000"
			if($(input[name=email]).value == "请输入正确邮箱"){
				$(input[name=email]).value = ""
			}

		})
		$(.alertspan).style["display"] = "none"

		var interval = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/
		$(input[name=email]).on("blur",function(){
			if($(input[name=email]).value == ""){
				$(input[name=email]).value = "请输入正确邮箱"
				$(input[name=email]).style["color"] = "#ccc"
				$(.alertspan).style["display"] = "none"
			}else{
				var namevalue = $(input[name=email]).value
				var reg = interval.test(namevalue)
				if(!reg){
					$(input[name=email]).style["color"] = "#ff0000"
					$(.alertspan).style["display"] = "block"
				}else{
					$(.alertspan).style["display"] = "none"
				}
			}
		})

		function reminder(){
			var cnt = 2;
			self.timer(500, function() {
				if(cnt <= 0) {
					//返回false则停止定时器
					$(#messtip).style["display"] = "none"
					return false;
				}
				cnt--;
				return true;
			});
		}
		function loginfun(userName,userPass){
			var resp = view.login(userName,userPass)
			if(resp.code == 0){
				$(#messtip).style["display"] = "block"
 				view.load("./view/index.html",false);
			}else{
				errors(resp.msg)
			}
    	}
		
	</script>
</body>

</html>

